package qz_rpt

import java.text.SimpleDateFormat

class WoStatusAnalysisController {

    def commonDataService
    def dynamicQueryService

    def index(Integer max) {
        def cellList = org.kdx.DataUtils.getCellList()
        def pageSizeList = org.kdx.DataUtils.getPageSizeList()

        [totalCount: 5, pageSize: 20, pageCurrent: 1, orderField: 'id', orderDirection: 'asc', pageSizeList: pageSizeList, cellList: cellList]
    }

    def woStatusAnalysis() {

        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        params.stepName = params.stepName
        params.state = params.state

        SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss')
        def startTime = params.startTime ? sdf.parse(params.startTime) : sdf.parse(sdf.format(new Date().clearTime() - 6))
        def endTime = params.endTime ? sdf.parse(params.endTime) : sdf.parse(sdf.format(new Date()))
        params.startTime = sdf.format(startTime)
        params.endTime = sdf.format(endTime)
        def woStatusAnalysisSum = []
        def tableHeadList = []
        def woStatusAnalysis = []
        def pageSizeList = [10, 20, 50, 100]
        def totalCount = 0
        params.SYS_QUERY_NAME = 'woStatusAnalysisStepList'
        def woStatusAnalysisStepList = dynamicQueryService.queryForList(params)

        params.SYS_QUERY_NAME = 'woStatusAnalysisState'
        def woStatusAnalysisState = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'woStatusAnalysisTotalGroup'
        def woStatusAnalysisTotalGroup = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'woStatusAnalysisDetailCate'
        def woStatusAnalysisDetailCate = dynamicQueryService.queryForList(params)
        if (params.EXPORT_CONTENT_NAME == 'Excel') {
            println(params.state)
            params.SYS_QUERY_NAME = 'woStatusAnalysis'
            woStatusAnalysis = dynamicQueryService.queryForList(params)
            tableHeadList = []
            if (woStatusAnalysis.size() > 0) {
                tableHeadList = woStatusAnalysis[0].keySet()
            }
            params.SYS_QUERY_NAME = 'woStatusAnalysisCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

            /*params.SYS_QUERY_NAME = 'woStatusAnalysisSum'
            def woStatusAnalysisSum = dynamicQueryService.queryForList(params)*/
        }


        /*params.SYS_QUERY_NAME = 'woStatusAnalysisLot'
        def woStatusAnalysisLot = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'woStatusAnalysisPartName'
        def woStatusAnalysisPartName = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'woStatusAnalysisPartDesc'
        def woStatusAnalysisPartDesc = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'woStatusAnalysisStepName'
        def woStatusAnalysisStepName = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'woStatusAnalysisStepDesc'
        def woStatusAnalysisStepDesc = dynamicQueryService.queryForList(params)

        woStatusAnalysis.clear()
        println(woStatusAnalysis)*/


        render(view: 'woStatusAnalysis', model: [totalCount                : totalCount, tableHeadList: tableHeadList,
                                                 pageSizeList              : pageSizeList, pageSize: pageSize,
                                                 startno                   : params.startno ?: '', endno: params.endno ?: '',
                                                 partName                  : params.partName ?: '', woStatusAnalysis: woStatusAnalysis,
                                                 partDesc                  : params.partDesc ?: '', stepName: params.stepName ?: '', stepDesc: params.stepDesc ?: '',
                                                 state                     : params.state ?: '', startTime: params.startTime ?: '', endTime: params.endTime ?: '',
                                                 lotId                     : params.lotId ?: '', totalGroup: params.totalGroup ?: '', detailCate: params.detailCate ?: '', eqp: params.eqp ?: '',
                                                 step                      : params.step ?: '', woStatusAnalysisStepList: woStatusAnalysisStepList, woStatusAnalysisState: woStatusAnalysisState,
                                                 woStatusAnalysisDetailCate: woStatusAnalysisDetailCate, woStatusAnalysisTotalGroup: woStatusAnalysisTotalGroup
                                                 /*woStatusAnalysisPartDesc:woStatusAnalysisPartDesc,woStatusAnalysisStepName:woStatusAnalysisStepName,
                                                 woStatusAnalysisStepDesc:woStatusAnalysisStepDesc,woStatusAnalysisState:woStatusAnalysisState,*/

        ])


    }
}
